cd "E:\NATO_ejpe_2017"
use me_data,clear
***Tables 1 and 2
tsset code_a year
drop if inlist(code_a,339,344)& year<2009
drop if inlist(code_a,317,349,355,360,366,367,368)& year<2004
drop if inlist(code_a,290,310,316)& year<1999
drop if code_a==230&year<1982
drop if code_a==395
xi i.code_a

eststo clear
eststo:ivreg2 me (me_sl= gdp_sl pop_sl)gdp pop _Icode_a* if year>=1960&year<=1974, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= gdp_uscont pop_uscont)gdp pop _Icode_a* if year>=1960&year<=1974, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= gdp_sldist pop_sldist)gdp pop _Icode_a* if year>=1960&year<=1974, small bw(3) kernel(bartlett) robust

eststo:ivreg2 me (me_sl= gdp_sl pop_sl)gdp pop _Icode_a* if year>=1974, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= gdp_uscont pop_uscont)gdp pop _Icode_a* if year>=1974, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= gdp_sldist pop_sldist)gdp pop _Icode_a* if year>=1974, small bw(3) kernel(bartlett) robust
esttab using table_1_2.csv,compress starlevels(* 0.10 ** 0.05 *** 0.01) replace

***Tables 3-10
drop if year<=1967
xi i.code_a 
gen MAD=0
replace MAD=1 if year>=1968 & year<1975
gen FLEX=0
replace FLEX=1 if year>=1975 & year<1991
gen mad_sl=MAD*me_sl
gen flex_sl=FLEX*me_sl
gen mad_sldist=MAD*me_sldist
gen flex_sldist=FLEX*me_sldist
gen mad_slcont=MAD*me_slcont
gen flex_slcont=FLEX*me_slcont
gen mad_uscont=MAD*me_uscont
gen flex_uscont=FLEX*me_uscont
gen mad_ruscont=MAD*me_ruscont
gen flex_ruscont=FLEX*me_ruscont
gen rus_cont=0
replace rus_cont=1 if inlist(code_a,2,255,290,310,355,360,366,367,368,385,390)
drop if code_a==395

eststo clear 
xi i.code_a 
eststo clear 
eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop _Icode_a*,  gmm2s bw(1) kernel(bartlett) robust
eststo:ivreg2 me (me_sl mad_sl= attack_sl gdp_sl pop_sl)attacks gdp pop _Icode_a*,  gmm2s bw(1) kernel(bartlett) robust
eststo:ivreg2 me (me_sl flex_sl= attack_sl gdp_sl pop_sl)attacks gdp pop _Icode_a*,  gmm2s  bw(1) kernel(bartlett) robust

eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop _Icode_a* if year>1990,  gmm2s bw(1) kernel(bartlett) robust
eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop rus_cont if year>1990,  gmm2s bw(1) kernel(bartlett) robust
eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop rus_me if year>1990,  gmm2s bw(1) kernel(bartlett) robust

eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop _Icode_a* if year>=1999,  gmm2s bw(1) kernel(bartlett) robust
eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop rus_cont  if year>=1999,  gmm2s bw(1) kernel(bartlett) robust
eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop rus_me  if year>=1999,  gmm2s bw(1) kernel(bartlett) robust
esttab using table_3_4.csv,compress starlevels(* 0.10 ** 0.05 *** 0.01) replace


eststo clear 
eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop _Icode_a*, small bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont mad_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop _Icode_a*, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont flex_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop _Icode_a*, small gmm2s bw(3) kernel(bartlett) robust

eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop _Icode_a* if year>1990, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop rus_cont if year>1990, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop rus_me _Icode_a* if year>1990, small gmm2s bw(3) kernel(bartlett) robust

eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop rus_cont if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop rus_me _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
esttab using table_6_7.csv.csv,compress starlevels(* 0.10 ** 0.05 *** 0.01) replace


eststo clear 
eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop _Icode_a*, small bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist mad_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop _Icode_a*, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist flex_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop _Icode_a*, small gmm2s bw(3) kernel(bartlett) robust

eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop _Icode_a* if year>1990, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop rus_cont if year>1990, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop rus_me _Icode_a* if year>1990, small gmm2s bw(3) kernel(bartlett) robust

eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop rus_cont if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop rus_me _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
esttab using table_8_9.csv.csv,compress starlevels(* 0.10 ** 0.05 *** 0.01) replace


keep if inlist(code_a,316,310,290,355,366,367,368,360,317,349,339,344)
eststo clear
xi i.code_a
eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sl= attack_sl gdp_sl pop_sl)attacks gdp pop rus_me  if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= attack_sldist gdp_sldist pop_sldist)attacks gdp pop rus_me _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= attack_uscont gdp_uscont pop_uscont)attacks gdp pop rus_me _Icode_a* if year>=1999, small gmm2s bw(3) kernel(bartlett) robust
esttab using table_5_10.csv,compress starlevels(* 0.10 ** 0.05 *** 0.01) replace



*******Tables 1A and 2A
use me1950,clear
tsset code_a year
drop if inlist(code_a,339,344)& year<2009
drop if inlist(code_a,317,349,355,360,366,367,368)& year<2004
drop if inlist(code_a,290,310,316)& year<1999
drop if code_a==230&year<1982
drop if code_a==395
xi i.code_a

eststo clear
eststo:ivreg2 me (me_sl= gdp_sl pop_sl)gdp pop _Icode_a* if year>=1960&year<=1974, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= gdp_uscont pop_uscont)gdp pop _Icode_a* if year>=1960&year<=1974, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= gdp_sldist pop_sldist)gdp pop _Icode_a* if year>=1960&year<=1974, small bw(3) kernel(bartlett) robust

eststo:ivreg2 me (me_sl= gdp_sl pop_sl)gdp pop _Icode_a* if year>=1974, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_uscont= gdp_uscont pop_uscont)gdp pop _Icode_a* if year>=1974, small gmm2s bw(3) kernel(bartlett) robust
eststo:ivreg2 me (me_sldist= gdp_sldist pop_sldist)gdp pop _Icode_a* if year>=1974, small bw(3) kernel(bartlett) robust
esttab using results_1A_2A.csv,compress starlevels(* 0.10 ** 0.05 *** 0.01) replace
